﻿using DAL;
using Permission.Web.Models;
using System.Linq;
using System.Web.Mvc;

namespace DianShang.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            using (ShopContext db = new ShopContext())
            {
               
                    var li = db.Product.ToList();
                ViewBag.image = db.Banner.Select(p => p.Image).ToList();
                return View(li);
            }
        }
  
        /// <summary>
        /// 安全退出
        /// </summary>
        /// <returns></returns>
        public ActionResult SignOut()
        {
            Session["login"] = null;
            return new RedirectResult("/Home/Index");

        }
        /// <summary>
        /// 登录页面
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        public ActionResult Login()
        {

            return View();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="loginname"></param>
        /// <param name="loginpwd"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Login(string loginname, string loginpwd)
        {
            if (string.IsNullOrWhiteSpace(loginname))
            {

                return Json(new UIResult(false, "账号不能为空"));
            }
            if (string.IsNullOrWhiteSpace(loginpwd))
            {

                return Json(new UIResult(false, "密码不能为空"));
            }



            Customer customer = Login_RegisterServers.SelectCustomer(loginname, loginpwd);
            if (customer != null)
            {
                Session["login"] = customer;
                return Json(new UIResult(true, "登录成功"));
            }
            else
            {

                return Json(new UIResult(false, "账号或者密码输入错误"));
            }


        }
        /// <summary>
        /// 注册页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Register()
        {
            return View();
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Register(Customer customer)
        {
            if (customer != null)
            {
                int res = Login_RegisterServers.ZhuChe(customer);
                if (res > 0)
                {
                    return Json(new UIResult(true, "注册成功"));
                }
                else
                {
                    return Json(new UIResult(false, "注册失败"));
                }
            }
            else
            {
                return Json(new UIResult(false, "未收到提交数据"));
            }

        }
        /// <summary>
        /// 数据库
        /// </summary>
        /// <returns></returns>
        public ActionResult ss()
        {
            ShopContext db = new ShopContext();
            var a = db.User.ToList();
            var b = db.Collection.ToList();
            var c = db.Customer.ToList();
            var d = db.DanPin.ToList();
            var e = db.GuiGe.ToList();
            var f = db.GuiGeZhi.ToList();
            var g = db.Logs.ToList();
            var h = db.Message.ToList();
            var i = db.Module.ToList();
            var j = db.Order.ToList();
            var k = db.OrderDetl.ToList();
            var l = db.Product.ToList();
            var m = db.ProductCategory.ToList();
            var n = db.Role.ToList();
            var o = db.Role_User.ToList();
            var p = db.ShoppingCart.ToList();
            var q = db.Sku_GuiGeZhi.ToList();
            var r = db.Spu_GuiGe.ToList();
            return View();
        }
    }
}